package com.yipai.datewidget;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.lxj.xpopup.XPopup;
import com.yipai.datewidget.booking.BookingPopupWindow;
import com.yipai.datewidget.booking.model.BookingInfoModel;
import com.yipai.datewidget.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding mActivityMainBinding;
    private BookingInfoModel mBookingInfoModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mActivityMainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);

        mActivityMainBinding.btnBookingPopup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                BookingPopupWindow bookingPopupWindow = new BookingPopupWindow(MainActivity.this);
                bookingPopupWindow.setBookingInfoSubmitListener(new BookingPopupWindow.BookingInfoSubmitListener() {
                    @Override
                    public void onSubmit(BookingInfoModel bookingInfoModel) {
                        Toast.makeText(MainActivity.this, "on submit", Toast.LENGTH_SHORT).show();
                        mBookingInfoModel = bookingInfoModel;
                    }
                }).setBookingInfoModel(mBookingInfoModel);

                new XPopup.Builder(MainActivity.this)
                        .moveUpToKeyboard(false)
                        .isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
                        .isViewMode(true)
                        .asCustom(bookingPopupWindow)
                        .show();
            }
        });
    }
}